//
//  XDVisitorView.swift
//  weibo
//
//  Created by lucy on 2016/10/23.
//  Copyright © 2016年 com.huashengHuaSheng. All rights reserved.
//

import UIKit

class XDVisitorView: UIView {

    var closure :(()->())?
    
    //MARK-重写初始化方法
    override init(frame: CGRect){
        super.init(frame:frame)
    
        //设置UI
        setupUI()

    }
    
    //MARK-添加首页圆圈图片动画
    private func setupCircleImageAnimation(){
    
        let anim = CABasicAnimation(keyPath:"transform.rotation")
        anim.duration = 20
        anim.toValue = M_PI*2
        anim.repeatCount = MAXFLOAT
        anim.isRemovedOnCompletion = false
        circleImage.layer.add(anim, forKey: nil)
    
    
    
    }
    
    
    
    //MARK-判断visitor的信息
    func setupVisitorInfo(imageName: String?, title: String?){
    
        if let imageName = imageName,let title = title{
        
            iconImage.image = UIImage(named: imageName)
            textLabel.text = title
            circleImage.isHidden = true

        }else{
        
            setupCircleImageAnimation()
        
        }
    
    
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    //MARK-自定义视图
    
    private func setupUI(){
    
//        backgroundColor = RandomColor()
        backgroundColor = UIColor(white: 236, alpha: 1)
        addSubview(circleImage)
        addSubview(maskImage)
        addSubview(iconImage)
        addSubview(textLabel)
        addSubview(registerBtn)
        addSubview(loginBtn)
        
        //添加圆圈图案的约束
        circleImage.snp_makeConstraints { (make) in
            
            make.center.equalTo(self)
        }
        
        maskImage.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        
        iconImage.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        
        textLabel .snp_makeConstraints { (make) in
            make.width.equalTo(230)
            make.centerX.equalTo(self)
            make.top.equalTo(maskImage.snp_bottom).offset(20)
        }
        
        registerBtn.snp_makeConstraints { (make) in
            make.top.equalTo(textLabel.snp_bottom).offset(20)
            make.left.equalTo(textLabel.snp_left).offset(0)
            make.size.equalTo(CGSize(width: 100, height: 35))
        }
        
        loginBtn.snp_makeConstraints { (make) in
            make.top.equalTo(textLabel.snp_bottom).offset(20)
            make.right.equalTo(textLabel.snp_right).offset(0)
            make.size.equalTo(CGSize(width: 100, height: 35))
        }
    
    }
    
    
    //MARK-登录和注册按钮点击事件
    @objc private func loginClick(){
    
//        print("按钮点击")
        closure?()
    
    }
    
    
    //MARK-加载访客视图
    //圆圈图案
    fileprivate lazy var circleImage: UIImageView = UIImageView(imageViewName:"visitordiscover_feed_image_smallicon")
    
    //遮挡层图案
    fileprivate lazy var maskImage: UIImageView = UIImageView(imageViewName:"visitordiscover_feed_mask_smallicon")
    
    //icon图案
    fileprivate lazy var iconImage: UIImageView = UIImageView(imageViewName:"visitordiscover_feed_image_house")
    
    //文字
    fileprivate lazy var textLabel: UILabel = {
    
        let lab = UILabel(textColor: UIColor.darkGray, textSize: XDNormalSizeFont, textContent: "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜")
    
        lab.numberOfLines = 0
        lab.textAlignment = .center
        return lab
    
    }()
    
    //注册按钮
    fileprivate lazy var registerBtn = UIButton(setBackgoundImageName: "common_button_white", title: "注册", titleFont: XDNormalSizeFont, titleColor: THEMECOLOR, target: self, action: #selector(loginClick))
    
    //登录按钮
    fileprivate lazy var loginBtn = UIButton(setBackgoundImageName: "common_button_white", title: "登录", titleFont: XDNormalSizeFont, titleColor: THEMECOLOR, target: self, action: #selector(loginClick))

    


}



















